package jobs;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.util.ToolRunner;

import util.BaselineTasking;
import util.BaselineUtilities;

public class BaselineJobs {

	
	public static void main(String args[]) throws Exception {
	
		if (args.length != 1) {
			System.err.println("Please specify a configuration file");
			System.exit(-1);
		}
		List<BaselineTasking> taskingList = new ArrayList<BaselineTasking>();
		try {
			taskingList = BaselineUtilities.processingConfigFile(args[0]);
		}
		catch (FileNotFoundException ex) {
			System.err.println("Specified configuration file does not exist");
		}
		
		for (BaselineTasking task : taskingList) {
			System.out.print("Instantiating new: " + task.getCls().getCanonicalName() + " with parameters: ");
			for (String string : task.getArgs()) {
				System.out.print(string + " ");
			}
			System.out.print("\n");
			int exitCode = ToolRunner.run(task.getCls().newInstance(), task.getArgs());
			System.out.println("Received exit status: " + exitCode + ". Now pausing for " + task.getPause() + "ms");
			BaselineUtilities.pause(task.getPause());
		}
		
		System.out.println("All tasks despatched. Ending.");
		
		//int res = ToolRunner.run(new WordCount(), args);
		//System.exit(res);
		
	}
}
